package module;

import java.nio.channels.SelectableChannel;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import bean.Item;
import bean.Mader;
import bean.ResultFlag;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

import DateBase.Datebase;

public class DetailModule {
	Datebase con=new Datebase();
	Connection conn=(Connection) con.getConnection();
	public ArrayList getItemMsg(int id) throws SQLException{
		String sql="select * from shop where shopid="+id+"";
		Statement st=(Statement) conn.createStatement();
		ResultSet rs =  st.executeQuery(sql);
		ArrayList list=new ArrayList();
		while(rs.next()){
			Item item=new Item();
			item.setId(rs.getInt("shopid"));
			item.setName(rs.getString("shopname"));
			item.setInformation(rs.getString("shopinformation"));
			item.setPicture(rs.getString("picture"));
			item.setPrice(rs.getFloat("price"));
			item.setNum(rs.getInt("num"));
			list.add(item);
		}
		return list;
	}
	public int addCart(int id,int num,String name,String picture,int userId,float price) throws SQLException{
		String sql="insert into car(shopid,num,shopname,picture,userid,price) values("+id+","+num+",'"+name+"','"+picture+"',"+userId+","+price+")";
		Statement st=(Statement) conn.createStatement();
		int flag=st.executeUpdate(sql);
		return flag;
	}
	
	
}
